 import { bezierSwipe } from '@/utils';

 const action = {
    swipeAction: () => {
        let x1 = random(300, 800);
        let y1 = random(1600, 1800);
        let x2 = random(300, 800);
        let y2 = random(500, 700);
        let duration  = random(200, 500);
        bezierSwipe(x1, y1, x2, y2, duration);
    },
    clickAction: (x, y) => {
        device.sdkInt < 24 ?
        Tap(x, y) :
        click(x, y);
    },
    homeAction: () => {
        device.sdkInt < 24 ?
        Home() :
        home();
    },
    backAction: () => {
        device.sdkInt < 24 ?
        Back() :
        back();
    },
    sleepAction: (s, e) => {
        if ((s || s === 0) && e) {
            sleep(random(s, e));
        } else if (s && e === undefined) {
            sleep(random(100, s));
        } else {
            sleep(random(4000, 7000));
        }
    }
}
const dyBtns = {
    likeBtn: () => descStartsWith('未选中').visibleToUser().findOnce(),
    commentBtn: () => descStartsWith('评论').visibleToUser().findOnce(),
    commentCount:  () => {
        const commentDesc = descStartsWith('评论').visibleToUser().findOnce().desc();
        const reg = /[^\d+(\.\d+)?$]/g;
        let commentCount = commentDesc.replace(reg, "");
        if (commentCount.includes('.')) {
            return commentCount * 10000;
        }
        return ~~commentCount;
    },
    qingshaonian: () => textContains('我知道了').visibleToUser().findOnce(),
    commentInput: () => text('留下你的精彩评论吧').findOnce(),
    submitCommitBtn: () => desc('发送').findOnce(),
    followBtn: () => descStartsWith('关注').visibleToUser().findOnce(),
    relayBtn: () => descStartsWith('分享').visibleToUser().findOnce(),
    relayBoxBtn: () => textContains("转发").visibleToUser().findOnce().parent(),
    relayPageBtn: () => textContains("转发到日常").visibleToUser().findOnce().parent().parent(),
    getVideoTit: () => id('com.ss.android.ugc.aweme:id/desc').visibleToUser().findOnce(),
    getVideoUserName: () => id('com.ss.android.ugc.aweme:id/title').visibleToUser().findOnce(),
    hasLiveBtn: () => text('点击进入直播间').visibleToUser().findOnce(),
    hasfristInAd: () => text('跳过广告').visibleToUser().findOnce(),
    collectFun: () => {
        const { width, height } = device;
        press(width / 2 + random(-100, 100) , height/2 + random(-100, 100), 1500);
        sleep(500);
        const collect = textContains("收藏").visibleToUser().findOnce().parent();
        if (!collect) {
            console.error('[收藏]-收藏控件查找异常');
            return;
        }
        collect.click();
        console.info('已收藏');
    },
    hasUpdateBtn: () => className("android.widget.TextView").visibleToUser().text("以后再说").findOne(1000),
    browseHomePage: () => {
        console.log('浏览主页');
    }
};
export {
    action,
    dyBtns
}